<!DOCTYPE html>

% # variables:
% # book sidebar

% import lonote.translate
% g = lonote.translate.get_gettext_func()


% import os.path
% import os
% import datetime as DT
% import xml.etree.ElementTree as ET

% import civa.putil

% booktitle = book.title()
% bookuuid = book.book_uuid()
% ebook = ET.fromstring(book.book_xml())
% page_count = len(ebook.findall('.//note')) + 1

% title = g('Management of {}').format(book.title())
<html lang="">
    <head>
        <meta charset="utf-8" />
        <title>{{!title}}</title>
        <meta name="description" content="{{booktitle}} Configure" />

        <script src="/static/js/jquery-1.9.1.js"></script>
        <script src="/static/js/jquery-ui-1.10.2.custom.min.js"></script>

        <script src="/static/js/URI.js"></script>
        <script src="/static/js/shortcut.js"></script>
        <script src="/static/js/lonote.js"></script>

        <link rel="stylesheet" href="/static/css/jqueryui-default/jquery-ui-1.10.2.custom.min.css" />
        <link rel="stylesheet" href="/static/css/default.css" type="text/css" />
        <link rel="stylesheet" href="/static/css/config.css" type="text/css" />
        <!--
        <script>
            // 自動增加行高，可放到 keyup 中
            function auto_height(textarea){
                var adjustedHeight=textarea.clientHeight;
                adjustedHeight=Math.max(textarea.scrollHeight, adjustedHeight);
                if (adjustedHeight>textarea.clientHeight){
                    textarea.style.height=adjustedHeight+'px';
                }
                // 先縮短再伸長
                // textarea.style.height = 10 + 'px';
                //textarea.style.height = textarea.scrollHeight + 'px';
            };
        </script>
        <script>
            function init_textarea(){
                $('textarea').each(function(index, elem){ auto_height(elem); });
            }
            $(document).ready(init_textarea);
        </script>
        <style>
            /* textarea { overflow: hidden; } */
        </style>
        -->
    </head>

    <body>
        <div id="content_column">
            <header>
                <h1>{{!title}}</h1>
            </header>
            <article id="config_content">
                <img src="/static/lo/lo_1_happy_2.png" style="float: left;" />
                <p>{{!g('Oh! You can manage your notebook in this page!')}}</p>
                <p>{{!g('And I will give you some info about this book... here!')}}</p>
                <table class="bookinfo">
                    <!-- <tr><th>item</th><th>value</th></tr> -->
                    <tr><td>{{!g('Page Count')}}</td><td>{{page_count}}</td></tr>
                <table>
                <!--
                <ul>
                    <li><a href="#stylesheet">Stylesheet</a></li>
                    <li><a href="#extrahead">Extra Head</a></li>
                </ul>
                -->
                <p style="clear: both;"><br/></p>

                <a name="stylesheet"></a><h2>{{!g('Stylesheet')}}</h2>
                <p class="description">{{!g('Changing appearance by some CSS code.')}}</p>
                <p class="description">{{!g('Hint: All your note content are under the "#main_content" element.')}}</p>
                <form method="POST" action="/extra/{{bookuuid}}/book.css?uploadmode=data">
                    % usercss = book.extra('book.css')
                    % usercss_default = '@charset "utf8";\n\n/* For example: Set article\'s background color as gray... */\n\n/*\n\n#main_content {\n    background-color: gray;\n}\n\n*/'
                    % value_text = g('CSS Update')
                    <input value="{{value_text}}" type="submit" /><br/>
                    <textarea class="ui-state-highlight" name="data" rows="30" cols="60">{{usercss or usercss_default}}</textarea>
                </form>
                <p><br/></p>

                <a name="extrahead"></a><h2>{{!g('Extra Head')}}</h2>
                <p class="description">{{!g('The following content will be insert to all note page\'s head block.')}}</p>
                <p class="description">{{!g('Hint: You can import some extra setting for every note page.')}}</p>
                <form method="POST" action="/extra/{{bookuuid}}/extra_head?uploadmode=data">
                    % extrahead = book.extra('extra_head')
                    % extrahead_default = '<!-- Recommend to using one of the extra theme: light.css, moonlight.css, orange.css -->\n<!-- <link rel="stylesheet" href="/static/css/extra/light.css" /> -->\n\n<!-- Can import other js library. EX: MathJax -->\n<!-- <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML.js"></script> -->'
                    % value_text = g('Extra Head Update')
                    <input value="{{value_text}}" type="submit" /><br/>
                    <textarea class="ui-state-highlight" name="data" rows="15" cols="60">{{extrahead or extrahead_default}}</textarea>
                </form>
                <p><br/></p>

                <h2>{{!g('Insert Wrapper')}}</h2>
                <p class="description">{{!g('Following template can use for html source insert. <b>{THIS}</b> represent the source code you want to insert.')}}</p>
                <form method="POST" action="/extra/{{bookuuid}}/insert_wrapper?uploadmode=dict">
                    % value_text = g('Wrapper Update')
                    <input value="{{value_text}}" type="submit" /><br/>
                    <table style="width: 95%">
                    <tr><th style="width: 100px;">{{!g('Name')}}</th><th>{{!g('Wrapper Format')}}</th></tr>
                    % iw = book.extra('insert_wrapper')
                    % if iw:
                        % for key, val in iw.items():
                            <tr><td><input class="ui-state-highlight" name="key" value="{{key}}" type="text"/></td><td><input class="ui-state-highlight" name="value" value="{{val}}" type="text"/></td></tr>
                        % end
                    % else: # default
                        <tr><td><input class="ui-state-highlight" name="key" value="No Wrapper" type="text"/></td><td><input class="ui-state-highlight" name="value" value="{THIS}" type="text"/></td></tr>
                        <tr><td><input class="ui-state-highlight" name="key" value="Inline Code" type="text"/></td><td><input class="ui-state-highlight" name="value" value="<code>{THIS}</code>" type="text"/></td></tr>
                        <tr><td><input class="ui-state-highlight" name="key" value="Key Press" type="text"/></td><td><input class="ui-state-highlight" name="value" value="<span class='keypress'>{THIS}</span>" type="text"/></td></tr>
                        <tr><td><input class="ui-state-highlight" name="key" value="Todo Item" type="text"/></td><td><input class="ui-state-highlight" name="value" value="<input class='todo-item-checkbox' type='checkbox' onclick='if(!$(this).attr(&quot;checked&quot;)){$(this).attr(&quot;checked&quot;, &quot;checked&quot;)}else{$(this).removeAttr(&quot;checked&quot;)};' /> <span class='todo-item-text'>{THIS}</span> " type="text"/></td></tr>
                    % end
                    <tr><td><input class="ui-state-highlight" name="key" value="" type="text"/></td><td><input class="ui-state-highlight" name="value" value="" type="text"/></td></tr>
                    </table>
                </form>
                <p><br/></p>

                <h2>{{!g('Flush & Download')}}</h2>
                % fpath = book.fpath
                % fname = os.path.basename(fpath)

                <p class="description">{{!g('Download your whole notebook.')}}</p>
                <form method="POST" action="/config/book/{{bookuuid}}/{{fname}}?cmd=flush">
                    % text = g('Flush & Download the Current Version')
                    <input value="{{text}}" type="submit" /><br/>
                </form>

                <form method="POST" action="/config/book/{{bookuuid}}/{{fname}}?cmd=get">
                    % stat = os.stat(fpath)
                    % size_mb = "{:.3}".format(stat.st_size / 1024 / 1024)
                    % mtime = DT.datetime.fromtimestamp(stat.st_mtime).strftime('%Y-%m-%d %H:%M:%S %z')
                    % text = g('Download the Last Flush Version')
                    % text2 = g('Modified time (guess): {mtime} Size: {size_mb} MB').format(mtime = mtime, size_mb = size_mb)
                    <input value="{{text}}" type="submit" title="{{text2}}" /><br/>
                </form>

                <form method="POST" action="/config/book/{{bookuuid}}/{{fname}}?cmd=get_backup">
                    % bak_fpath = civa.putil.chext(fpath, 'bak')
                    % text = g('Download the Backup Version')
                    % if os.path.isfile(bak_fpath):
                        % bak_stat = os.stat(bak_fpath)
                        % bak_size_mb = "{:.3}".format(bak_stat.st_size / 1024 / 1024)
                        % bak_mtime = DT.datetime.fromtimestamp(bak_stat.st_mtime).strftime('%Y-%m-%d %H:%M:%S %z')
                        % text2 = g('Modified time (guess): {mtime} Size: {size_mb} MB').format(mtime = bak_mtime, size_mb = bak_size_mb)
                        <input value="{{text}}" type="submit" title="{{text2}}"/>
                    % else:
                        % text2 = g('No backup version available.')
                        <input value="{{text}}" type="submit" disabled="disabled" title="{{text2}}" />
                    % end

                </form>
                <p><br/></p>

                <h2>{{!g('Search Index')}}</h2>
                <p class="description">{{!g('If you move a book between on two or more server manually, the search result may not fully correct.')}}</p>
                <p class="description">{{!g('For fix it, please re-index your notebook.')}}</p>
                <form method="POST" action="?cmd=reindex">
                    % title_text = g('Bigger book need more time to do it, please wait...')
                    % value_text = g('Re-index This Notebook')
                    <input value="{{value_text}}" type="submit" title="{{title_text}}" />
                </form>
                <p><br/></p>

                <img src="/static/lo/lo_1_angry_1.png" style="float: left;"/>
                <h2>{{!g('Delete Book')}}</h2>
                <p class="description">{{!g('Destroy a book is an immoral decision! Don\'t do that!')}}</p>
                <div style="text-align: center;">
                    <form method="POST" action="?cmd=kill">
                        % confirm_text = g('Are you really want to delete {} ...?').format(booktitle)
                        % title_text = g('This\'s not a good idea...')
                        % value_text = g('Delete!')
                        <input class="icon" style="background-color: darkred; color: red; border: 1px solid #000000; border-radius: 3px;" value="{{value_text}}" type="submit" title="{{title_text}}" onclick="return confirm('{{confirm_text}}');" />
                        <input name="fname" type="hidden" value="{{fname}}" />
                    </form>
                </div>
                <p style="clear: both;"><br/></p>

            </article>
        </div>

        <script>
            $(window).on('load', function(){
                lo.scr.restore();
                lo.key.search_ready();
            });

            $(window).on('beforeunload', lo.scr.save);
            $(window).blur(lo.scr.save);
            $('#config_content').tooltip();

        </script>

        <!-- 讀入 sidebar -->
        {{!sidebar}}
        <!--
        <script>
            function sidebar_load(){
                function get_success(data){
                    $('body').append(data);
                };
                var sidebar_loc = '/sidebar';
                $.get(sidebar_loc, get_success);
            };
            $(window).one('load', sidebar_load);
        </script>
        -->

        <script>
            shortcut.add("F4",function(){
                location.assign('/last');
            });
        </script>

    </body>
</html>


